package thread;
public class SyncDemo4 {
    public static void main(String[] args) {
        Boo boo=new Boo();
        new Thread(boo::methodA).start();
        new Thread(boo::methodB).start();
    }
}
class  Boo{
    public synchronized void methodA(){
        Thread t =Thread.currentThread();
        System.out.println(t.getName()+"正在执行methodA");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(t.getName()+"执行methodA完毕");
    }
            public   void methodB() {
                synchronized (this) {
                    Thread t = Thread.currentThread();
                    System.out.println(t.getName() + "正在执行methodB");
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(t.getName() + "执行methodB完毕");
                }
            }
}